package bairui.international.console.web.controller.product.category;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.servlet.ModelAndView;

import com.lianjing.sh.project.config.web.Project_Config_Web_PageTemplate;
import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.module.context.ModuleContext;
import com.lianjing.sh.spring.web.controller.enhance.navigations.context.NavigationContext;

import bairui.international.console.web.controller.product.C_Product_Index_Left;
import bairui.international.model.domain.jpa.TB_ProductCategory;
import bairui.international.service.Service_ProductCategory;

/**
 *
 * 编辑
 *
 * @generated
 * 
 * @see STest_C_Product_Category_Edit_EditAccess 测试
 *
 */
@Controller
public class C_Product_Category_Edit_EditAccess
 extends SC_Product_Category_Edit_EditAccess 
{
	
	@Autowired private Service_ProductCategory service_ProductCategory;
//	@Autowired private Service_ProductProperty service_ProductProperty;
	
	/**
	 * 访问编辑页面
	 */
	@Action(EditAccess.class)
	@GetMapping(EditAccess.RequestMappingValue)
	public ModelAndView editAccess(
		ModelMap map, HttpServletRequest request,
		NavigationContext navigationContext, ModuleContext moduleContext, 
		@PathVariable(name=EditAccess.PathVariableName.Id) long id
	) throws Exception {
		TB_ProductCategory bean = service_ProductCategory.findById(id);
//		List<TB_ProductProperty> ps = service_ProductProperty
//			.list(it->it.productCategories.any().eq(bean))
//			.stream()
//			.map(it->{
//				TB_ProductProperty p = new TB_ProductProperty();
//					p.setName(it.getName());
//					p.setId(it.getId());
//				return p;
//			})
//			.collect(Collectors.toList());
//		bean.setProductProperties(ps);
		/* 侧边栏 */
		C_Product_Index_Left.importPage(map);
		/* 模块 */
		moduleContext
			.addModule(module_Edit.module(
					bean,
					new C_Product_Category_Edit_Edit.Edit.Operate(){
						@Override public Object getId() { return id; }
						@Override public com.lianjing.sh.spring.web.controller.base.operate.OperateSupport returnTo() {
							return new C_Product_Category_Tree_TreeAccess.TreeAccess.Operate() {
								@Override public Object getParentId() {
									return null;
								}
							};
						};
					}
//					service_ProductProperty.list(it->it.state.eq(State_UpDown.Uped))
				));
		//
		return Project_Config_Web_PageTemplate.Admin_Common(request);
	}
	

}
